﻿using System;
using System.Collections.Generic;
using System.Text;

namespace EnCor.ObjectBuilder
{
    public class BuilderContext : IBuilderContext
    {
        private Dictionary<KeyValuePair<string, Type>, object> _Directory = new Dictionary<KeyValuePair<string, Type>, object>();

        public void AddExtension<T>(T instance)
        {
            AddExtension<T>(null, instance);
        }

        public void AddExtension<T>(string name, T instance)
        {
            KeyValuePair<string, Type> key = new KeyValuePair<string, Type>(name, typeof(T));

            _Directory.Add(key, instance);
        }

        #region IBuilderContext Members

        public T GetExtension<T>()
        {
            return GetExtension<T>(null);
        }

        public T GetExtension<T>(string name) 
        {
            Object obj = null;
            KeyValuePair<string, Type> key = new KeyValuePair<string, Type>(name, typeof(T));
            if (_Directory.TryGetValue(key, out obj))
            {
                return (T)obj;
            }
            else
            {
                return default(T);
            }
        }

        public EnCor.Caching.ICacheManager GetCacheManager(string cacheManagerName)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
